package com.example.enjoyfood.Adapter


import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.enjoyfood.R
import com.example.enjoyfood.Recipe

class RecipesAdapter(private val context: Context, private val recipes: List<Recipe>) : BaseAdapter() {

    override fun getCount(): Int = recipes.size

    override fun getItem(position: Int): Any = recipes[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val view: View = convertView ?: LayoutInflater.from(context).inflate(R.layout.item_recipe, parent, false)

        val imageView: ImageView = view.findViewById(R.id.recipe_image)
        val textView: TextView = view.findViewById(R.id.recipe_name)

        val recipe = recipes[position]
        imageView.setImageResource(recipe.imageResId)
        textView.text = recipe.name

        return view
    }
}